package com.mail.server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.model.db.SmsHomeBrand;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import com.mail.server.service.SmsHomeBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页推荐品牌表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/home/brand")
public class SmsHomeBrandController {

    @Autowired
    private SmsHomeBrandService smsHomeBrandService;

    @PostMapping("/create")
    public R<String> addBrand(@RequestBody List<SmsHomeBrand> homeBrandList){
        smsHomeBrandService.addBrand(homeBrandList);
        return R.success("");
    }

    @PostMapping("/delete")
    public R<String> deleteBrand(@RequestParam("ids") List<Long> ids){
        smsHomeBrandService.deleteBrand(ids);
        return R.success("");
    }

    @GetMapping("/list")
    public R<PageResult> getBrandByPage(@RequestParam(defaultValue = "1") Long pageNum,
                                    @RequestParam(defaultValue = "10") Long pageSize,
                                    String brandName,
                                    Integer recommendStatus){
        PageResult page = smsHomeBrandService.getBrandByPage(pageNum,pageSize,brandName,recommendStatus);
        return R.success(page);
    }

    @PostMapping("/update/recommendStatus")
    public R<String> updateBrand(@RequestParam("ids") List<Long> ids,@RequestParam("recommendStatus") Integer recommendStatus){
        smsHomeBrandService.updateBrand(ids,recommendStatus);
        return R.success("");
    }

    @PostMapping("/update/sort/{id}")
    public R<String> updateSortBrand(@PathVariable("id") Long id,@RequestParam(required = false) Integer sort){
        smsHomeBrandService.updateSortBrand(id,sort);
        return R.success("");
    }
}
